package com.qf.studentmanager.service;

import com.qf.studentmanager.dao.ExamDao;
import com.qf.studentmanager.model.Exam;
import com.qf.studentmanager.model.RespPageBean;

import java.sql.SQLException;
import java.util.List;

public class ExamService {
    ExamDao examDao = new ExamDao();
    public RespPageBean getAllExamByPage(String page, String rows, String sort, String order, String gid, String cid) {
        if (page == null){
            page = "1";
        }
        if (rows == null){
            rows = "10";
        }
        if (sort == null){
            sort = "cid";
        }
        if (order == null){
            order ="asc";
        }
        RespPageBean respPageBean = new RespPageBean();
        Long total = examDao.getTotal(gid,cid);//根据年级和班级id查，

        int p = Integer.parseInt(page);
        int r = Integer.parseInt(rows);
        List<Exam> list = examDao.getExamByPage((p-1)* r,r,sort,order,gid,cid);

        respPageBean.setTotal(total);
        respPageBean.setRows(list);
        return respPageBean;

    }


    public Integer addExam(Exam exam) {
        try {
            Integer i =examDao.addExam(exam);
            return i;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return -1;
    }

    public Integer deleteExamByEid(String eid) {
        Integer i = null;
        try {
            i = examDao.deleteExamByEid(eid);
            return i;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return -1;
    }
}
